<template>
	<view class="qrcode">
		<view class="top d-flex">
			<u-image :src="data.goods_image" width="160rpx" height="160rpx" radius="12rpx"></u-image>
			<view style="margin-left: 30rpx;display: flex;flex: 1;flex-direction: column;">
				<view class="name ">{{ data.goods_name }}</view>
				<!-- <view class="date" v-for="(item,index) in data.consumption_type" :key="index">{{ item}}</view> -->
				<view v-if="data.sku_info">
					<view class="date">{{ data.sku_info}}</view>
				</view>
				<view class="venue_name" v-if="options.type == 'court'">{{ data.start_time }} - {{ data.end_time }}
				</view>
				<view class="venue_name"  v-if="options.type == 'card'">{{ data.yxq}}</view>
				<view class="venue_name" v-if="options.type == 'court'">{{data.court_name}}</view>
				<view class="venue_name" v-else>{{data.venue_name}}</view>
				<view class="share_a" v-if="data.field_type == 2"> 名额场 </view>
				<view class="share_a" style="color: coral;" v-if="data.field_type == 1"> 包场 </view>
				<view class="share_a" v-if="data.field_type == 3"> 拼团 </view>
			</view>
		</view>

		<view class="qrcode-wrapper">
			<view class="chooses flex-between" v-if="options.title == '我的场地'">
				<view class="my-menu">
					<view class="cates">
						<!-- <view class="cate-item pr" v-for="(item, index) in myMenuCate" :key="index"
							@click="onClickMenu(item,index)">
							<u-image :src="item.icon" width="80rpx" height="80rpx" :showMenuByLongpress="false">
							</u-image>
							<text>{{item.name}}</text>
						</view> -->
						<view class="cates" @click="onClickMenulist">
							<view class="cate-item pr">
								<u-image
									src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/6d8fb4fe0fe24689c66a224389590449da7693c7.png"
									width="80rpx" height="80rpx" :showMenuByLongpress="false">
								</u-image>
								<text>分享球场</text>
							</view>
						</view>
						<!-- <view class="catess" @click="chaoshi">
							<view class="cate-item pr">
								<u-image
									src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/2e073c45df1b1d871bd1f5abffcbf622507e2ab9.png"
									width="80rpx" height="80rpx" :showMenuByLongpress="false">
								</u-image>
								<text>超时出场</text>
							</view>
						</view>
						<view class="catesss" @click="dengguan">
							<view class="cate-item pr">
								<u-image
									src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/d21f70e273b2b1ddb76d969a8e8b784db555dd65.png"
									width="80rpx" height="80rpx" :showMenuByLongpress="false">
								</u-image>
								<text>开关灯光</text>
							</view>
						</view> -->
						<!-- <view class="catesss" @click="onClickMenu">
							<view class="cate-item pr">
								<u-image
									src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/d21f70e273b2b1ddb76d969a8e8b784db555dd65.png"
									width="80rpx" height="80rpx" :showMenuByLongpress="false">
								</u-image>
								<text>开关灯光1321</text>
							</view>
						</view> -->
					</view>
				</view>
			</view>
			<view class="choose flex-between" v-else>
				<view>{{ choose }}</view>
				<view class="d-flex align-center" @click="backToList">
					<view style="color: #8a8a8a; margin-right: 20rpx;">
						<view style="width: 260rpx;text-align: right;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">{{ data.goods_name }}</view>
					</view>
					<u-icon name="arrow-right" color="#e1e1e1" size="24rpx"></u-icon>
				</view>
			</view>
		
			<view class="d-flex align-center flex-column" :hidden="!vueShowModel">
				<view class="destroy-code">核销码：{{ code }}</view>
				<view class="tip">请在核验时出示，注意保管勿泄露</view>
				<!-- <u-image width="370rpx" height="370rpx"></u-image> -->
				<uQRCode ref="qrcode" canvas-id="qrcode" :value="code" size="185"></uQRCode>
				<!-- <view class="tip">请在核验时出示，注意保管勿泄露</view> -->
				<view class="tips" v-if="options.title == '我的场地'">
					<view class="" v-if="options.beShare == 0">
						开场前<text style="color: #ffaa00;">{{ data.permit_in_time }}</text> 分钟允许进场；结束后<text
							style="color: #ffaa00;">{{ data.permit_in_time }}</text> 分钟离场，请勿超时！</view>
				</view>
			</view>
		</view
		<div class="vueMdelBox">
			<div :hidden="vueShowModel" class="vueContant">
				<div class="vueTitle">是否申请开灯！</div>
				<!-- <div class="vueDetail">
					<u-tag v-for="(item2,index2) in data_specs" :key="index2" :text="item2.name" type="warning"
						:bgColor="
					    data_name.indexOf(item2) > -1
					      ? '#2F75FA'
					      : '#EFEFEF'
					  " :borderColor="
					    data_name.indexOf(item2) > -1 ? '#2F75FA' : 'rgba(0,0,0,0)'
					  " :color="data_name.indexOf(item2) > -1 ? '#ffffff' : '#333'" @click="data_specss(item2,index2)" size="large" />
		
				</div> -->
				<!-- <view class="" style="width: 80%;height: auto;margin-left: 10%;">
					<u-textarea v-model="data.content" placeholder="请输入挂失理由" border="none" height="100"></u-textarea>
				</view> -->
				<div class="vueBtn">
					<u-button text="我再想想" shape="circle" size="small"
						color="linear-gradient(0deg, rgb(211, 211, 211) 0%, rgb(211, 211, 211) 65%)" @click="cancel()">
					</u-button>
					<u-button text="提交" shape="circle" size="small"
						color="linear-gradient(0deg, rgb(47, 117, 250) 0%, rgb(82, 142, 255) 65%)" @click="cancel()">
					</u-button>
				</div>
			</div>
			<div class="vueBgdCol" :hidden="vueShowModel" @click="setting()"></div>
		</div>
		<view class="" style="margin-top: 20rpx;">
			<u-swiper :list="list1" radius=0></u-swiper>
		</view>
	</view>
</template>

<script>
	import uQRCode from '@/uni_modules/Sansnn-uQRCode/components/u-qrcode/u-qrcode.vue'
	const person = require("@/api/personal/index.js");
	export default {
		components: {
			uQRCode
		},
		data() {
			return {
				list1: [],
				data: {},
				options: {},
				code: '',
				choose: "",
				timer: null,
				myMenuCate: [{
						name: '分享球场',
						icon: 'https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/6d8fb4fe0fe24689c66a224389590449da7693c7.png'
					},
					{
						name: '超时出场',
						icon: 'https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/2e073c45df1b1d871bd1f5abffcbf622507e2ab9.png'
					},
					{
						name: '开关灯光',
						icon: 'https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/d21f70e273b2b1ddb76d969a8e8b784db555dd65.png'
					}
				],
				codes: "",
				codes: '',
				not_in_time: '',
				vueShowModel: true, //默认不显示
				chosen_id: '',
				is_over: '',
				id:''
			}
		},
		onLoad(options) {
			console.log(options, '111')
			this.timer = null;
			this.getChannelBanner()
			this.options = options;

			uni.setNavigationBarTitle({
				title: options.title
			});
			if (options.type == 'ticket') {
				this.getMyTicketDetail();
				this.choose = '选择票'
			} else if (options.type == 'card') {
				this.getMyCardDetail();
				this.choose = '选择卡'
			} else if (options.type == 'court') {
				if (this.options.beShare == '0') {
					this.options.sender = ''
					this.getMyCourtDetail()
				}
				if (this.options.beShare != '0') {
					this.getMyCourtDetail()
				}
			}
			// if(options.title == '我的票包'){
			// 	this.getMyTicketDetail();
			// }else if(options.title == '我的卡包'){
			// 	this.getMyCardDetail();
			// }else if(options.title == '我的场地'){
			// 	if(this.options.beShare == '0'){
			// 		this.options.sender = ''
			// 		this.getMyCourtDetail()
			// 	}
			// 	if(this.options.beShare != '0'){
			// 		this.getMyCourtDetail()
			// 	}
			// }			
		},
		onShow() {
			let that = this;
			that.timer = null;
			clearInterval(that.timer);
			that.timer = setInterval(() => {
				if (that.options.type == 'ticket') {
					that.getMyTicketDetail();
					that.choose = '选择票'
				} else if (that.options.type == 'card') {
					that.getMyCardDetail();
					that.choose = '选择卡'
				} else if (that.options.type == 'court') {
					if (that.options.beShare == '0') {
						that.options.sender = ''
						that.getMyCourtDetail()
					}
					if (that.options.beShare != '0') {
						that.getMyCourtDetail()
					}
				}
			}, 300000);
		},
		onUnload() {
			let that = this;
			clearInterval(that.timer);
			that.timer = null;
		},
		onHide() {
			let that = this;
			clearInterval(that.timer);
			that.timer = null;
		},
		methods: {
			async getChannelBanner() {
				let postData = {
					app_id: this.$https.weixinAppId,
					project_id: getApp().globalData.projectId,
				};
				let res = await person.getChannelBanner(postData);
				if (res.code == 1) {
					this.list1 = res.data.result.channel_banner_code
				}
			},
			// onClickMenu(item, index) {
			// 	if (index == 0) {
			// 		uni.navigateTo({
			// 			url: '../../../page_venues/pages/venuesDetail/sharedBy/sharedBy?id=' + this.options.id +
			// 				"&court_no=" + this.codes +
			// 				"&beShare=" + this.options.beShare
			// 		})
			// 		var that = this;
			// 		clearInterval(that.timer);
			// 		that.timer = null;
			// 	} else if (index == 1) {
			// 		var that = this;
			// 		clearInterval(that.timer);
			// 		that.timer = null;
			// 		uni.navigateTo({
			// 			url: '/pages/overtime/index'
			// 		})
			// 	}
			// },
			onClickMenulist() {
				if (this.data.field_type != 2 && this.is_over != 1) {
					uni.navigateTo({
						url: '../../../page_venues/pages/venuesDetail/sharedBy/sharedBy?id=' + this.options.id +
							"&court_no=" + this.codes +
							"&beShare=" + this.options.beShare
					})
					var that = this;
					clearInterval(that.timer);
					that.timer = null;
				} else {
					uni.showToast({
						title: '您暂无分享权利。',
						icon: 'error',
						duration: 1500
					});
				}
			},
			// 获取我的票券详情
			async getMyTicketDetail() {
				let postData = {
					project_id: getApp().globalData.projectId,
					open_id: uni.getStorageSync("openid"),
					appid: this.$https.weixinAppId,
					ticketno: this.options.ticket_no
				}
				let res = await person.getMyTicketDetail(postData)
				if (res.code === 1) {
					this.data = res.data.ticketData
					// this.code = res.data.ticketData.ticket_no
					this.getDynamiclist()
				}
			},
			async getDynamiclist() {
				let params = {
					goods_type: '1',
					project_id: getApp().globalData.projectId,
					app_id: this.$https.weixinAppId,
					goods_id: this.data.id
				}
				let res = await person.getDynamicCode(params)
				if (res.code === 1) {
					this.code = res.data.result.code
				}
			},

			// 获取我的卡包详情
			async getMyCardDetail() {
				let params = {
					cardno: this.options.cardno,
					project_id: getApp().globalData.projectId,
					user_id: uni.getStorageSync('phone'),
					appid: this.$https.weixinAppId,
					open_id: uni.getStorageSync("openid"),
					id:this.options.id
				}
				let res = await person.getMyCardDetail(params)
				if (res.code === 1) {
					this.data = res.data.cardData
					// this.code = res.data.cardData.cardno
					this.getDynamicCode()
				}
			},
			async getDynamicCode() {
				let params = {
					goods_type: '2',
					project_id: getApp().globalData.projectId,
					app_id: this.$https.weixinAppId,
					goods_id: this.data.id
				}
				let res = await person.getDynamicCode(params)
				if (res.code === 1) {
					this.code = res.data.result.code
				}
			},
			// 获取我的场地详情
			async getMyCourtDetail() {
				let param_s = {
					project_id: getApp().globalData.projectId,
					app_id: this.$https.weixinAppId,
					open_id: uni.getStorageSync("openid"),
					ticketno: this.options.court_no,
					sender: this.options.sender,
					product_id: this.options.product_id,
				}
				let res = await person.getMyCourtDetail(param_s)
				if (res.code === 1) {
					this.data = res.data.ticketData
					this.code = res.data.ticketData.court_no
					this.codes = res.data.ticketData.court_no
					this.chosen_id = res.data.ticketData.id
					this.is_over = res.data.ticketData.is_over
					uni.setNavigationBarTitle({
						title: this.data.venue_name
					});

					let items = JSON.stringify(res.data.ticketData);
					uni.setStorageSync("wqzdy", items);

					var datas = uni.getStorageSync("wqzdy");
					var itemss = JSON.parse(datas)
					console.log(itemss, '2222222')
					this.getDynamicCodes()
				}
			},
			async getDynamicCodes() {
				let params = {
					goods_type: '3',
					project_id: getApp().globalData.projectId,
					app_id: this.$https.weixinAppId,
					goods_id: this.data.id,
					beshared: this.options.beShare,
					code: this.codes,
					open_id: uni.getStorageSync("openid"),
					choose_id: this.data.id
				}
				let res = await person.getDynamicCode(params)
				if (res.code === 1) {
					this.code = res.data.result.code
					this.not_in_time = res.data.result.not_in_time
				}
			},

			backToList() {
				uni.navigateBack({
					delta: 1
				})
			},
			chaoshi() {
				console.log(this.is_over, '123123')
				if (this.is_over == 1) {
					uni.navigateTo({
						url: '/pages_a/overtime/overtime?court_id=' + this.options.court_id +
							"&chosen_id=" + this.chosen_id
					})
				} else {
					uni.showModal({
						content: '您没有超时账单，请尽快离场。',
						showCancel: false,
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			// 点击按钮打开弹框
			vueToMdel() {
				this.vueShowModel = false;
			},
			// 点击蒙版按钮模态框消失
			setting() {
				this.vueShowModel = true;
			},
			// 点击取消按钮模态框消失
			cancel() {
				this.vueShowModel = true;
			},
			// 点击确定按钮模态框消失
			confirm() {
				this.vueShowModel = true;
			},
			dengguan() {
				if (this.not_in_time == 1) {
					// uni.showModal({
					// 	// title: data[1],
					// 	content: '当前时间不在订单时间范围',
					// 	showCancel: false,
					// 	success: function(res) {
					// 		if (res.confirm) {
					// 			console.log('用户点击确定');
					// 		} else if (res.cancel) {
					// 			console.log('用户点击取消');
					// 		}
					// 	}
					// });
					this.vueShowModel = false;
				}
			},
			fenxiang() {
				uni.navigateTo({
					url: '../../../page_venues/pages/venuesDetail/sharedBy/sharedBy?id=' + this.options.id +
						"&court_no=" + this.code
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	// @import url("@/static/css/personal/index.css");
	.qrcode {
		min-height: 100vh;
		background-color: #2f75fa;
		padding: 20rpx;
		padding-bottom: calc(20rpx + env(safe-area-inset-bottom));

		.top {
			border-radius: 20rpx;
			padding: 30rpx 24rpx;
			background-color: #fff;
			margin-bottom: 30rpx;

			.share_a {
				width: 140rpx;
				height: 60rpx;
				border-radius: 50%;
				position: absolute;
				top: 3.3%;
				right: 3rpx;
				font-size: 28rpx;
				color: #999999;
			}

			.name {
				font-weight: bold;
				color: #333;
				margin-bottom: 20rpx;
			}

			.date {
				background-color: rgb(240, 138, 34);
				color: rgb(255, 255, 255);
				font-size: 24rpx;
				border-radius: 100px;
				padding: 4rpx 20rpx;
				margin-right: 10rpx;
				font-weight: 550;
			}

			.venue_name {
				font-size: 30rpx;
				color: #000;
				margin-bottom: 20rpx;
			}
		}

		.qrcode-wrapper {
			border-radius: 10rpx;
			background-color: #fff;
			overflow: hidden;
			padding-bottom: 60rpx;

			.choose {
				background-color: #f7f7f7;
				padding: 49rpx 30rpx 51rpx 31rpx;
			}

			.chooses {
				background-color: #f7f7f7;
				padding: 75rpx 30rpx 80rpx 31rpx;

				.my-menu {
					position: absolute;
					// top: 240rpx;
					// left: 5%;
					transform: translate(-50%);
				}

				.cates {
					display: flex;
					justify-content: center;
					position: absolute;
					top: 50%;
					left: 22rpx;
					transform: translateY(-50%);
				}

				.catess {
					display: flex;
					justify-content: center;
					position: absolute;
					top: 50%;
					left: 210rpx;
					transform: translateY(-50%);
				}

				.catesss {
					display: flex;
					justify-content: center;
					position: absolute;
					top: 50%;
					left: 390rpx;
					transform: translateY(-50%);
				}

				.cate-item {
					width: 200rpx;
					font-size: 24rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
				}

				.cate-item text {
					margin-top: 10rpx;
				}

			}

			.destroy-code {
				color: #2f75fa;
				// margin: 40rpx 0;
				margin: 40rpx 0 20rpx 0;
			}

			.tip {
				margin: 10rpx 0 30rpx 0;
				color: #999;
				font-size: 28rpx;
			}

			.tips {
				margin-top: 20rpx;
				color: #999;
				font-size: 28rpx;
			}
		}

		.fenxiang {
			color: #fff;
			margin-top: 29rpx;
		}

		.vueBgdCol {
			position: fixed;
			top: 0%;
			left: 0%;
			width: 100%;
			height: 100%;
			background-color: black;
			z-index: 1001;
			-moz-opacity: 0.8;
			opacity: 0.8;
			filter: alpha(opacity=88);
		}

		.vueContant {
			position: fixed;
			top: 40%;
			left: 50%;
			width: 600rpx;
			height: 300rpx;
			margin-left: -305rpx;
			margin-top: -76px;
			background-color: white;
			z-index: 1002;
			overflow: auto;
			border-radius: 20rpx;
		}

		.vueTitle {
			display: flex;
			justify-content: center;
			font-size: 28rpx;
			padding-top: 55rpx;
			font-weight: 600;
		}

		.vueContants {
			position: fixed;
			top: 40%;
			left: 50%;
			width: 600rpx;
			height: 330rpx;
			margin-left: -320rpx;
			margin-top: -76px;
			background-color: white;
			z-index: 1002;
			overflow: auto;
			border-radius: 20rpx;
		}

		.vueTits {
			display: flex;
			justify-content: center;
			font-size: 28rpx;
			padding-top: 75rpx;
			font-weight: 600;
		}

		.vueDetail {
			font-size: 28rpx;
			color: #646566;
			display: flex;
			// justify-content: center;
			padding: 32rpx;
			height: 48rpx;
			margin-right: 20rpx;
		}

		/deep/.u-tag {
			margin-left: 20rpx;

		}

		/deep/.u-textarea {
			background-color: #f3f3f3;
			margin-top: 80rpx;
		}

		/deep/.u-button {
			width: 30%;
			height: 60rpx;
		}

		.vueBtn {
			display: flex;
			margin-top: 80rpx;
		}

		.vueBtns {
			display: flex;
			margin-top: 100rpx;
		}

		.vueBtn span {
			width: 320rpx;
			height: 96rpx;
			font-size: 24rpx;
			font-weight: 600;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.vueBtn span:first-child {
			border-top: 1px solid #ebedf0;
		}

		.vueBtn span:last-child {
			color: #ee0a24;
			border-top: 1px solid #ebedf0;
			border-left: 1px solid #ebedf0;
		}
	}
</style>
